<template>
	<view class="page-container">
		<view class="form-container">
			<view class="title">用户登录</view>
			<!-- 头像区域 -->
			<view class="logo">
				<image src="/static/mmao.jpg" class="avatar-img"></image>
			</view>
			<view class="input-group">
				<input type="text" v-model="username" placeholder="请输入用户名" class="input" auto-focus />
			</view>
			<view class="input-group">
				<input type="password" v-model="password" placeholder="请输入密码" class="input" />
			</view>
			<button class="btn login-btn" @click="handleLogin">登录</button>
			<view class="link-container">
				<text>还没有账号？</text>
				<text class="link" @click="goToRegister">立即注册</text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				username: 'zss',
				password: '123456'
			};
		},
		methods: {
			handleLogin() {
				if (!this.username) {
					return uni.showToast({ title: '请输入用户名', icon: 'none' });
				}
				if (!this.password) {
					return uni.showToast({ title: '请输入密码', icon: 'none' });
				}

				// 模拟登录成功（实际项目替换为接口请求）
				const app = getApp();
				app.globalData.userName = this.username;
				app.globalData.isLogin = true;

				uni.showToast({ title: '登录成功', icon: 'success' });
				
				// 登录后返回“我的页面”（关闭当前登录页，返回上一级）
				setTimeout(() => {
					uni.navigateBack({
						delta: 1 // 返回上一个页面（即“我的页面”）
					});
				}, 1000);
			},
			goToRegister() {
				uni.navigateTo({ url: '/pages/components/register/register' });
			}
		}
	};
</script>

<style scoped>
	/* 原有样式保持不变 */
	.page-container {
		display: flex;
		justify-content: center;
		padding: 40rpx 30rpx;
		background-color: #f9f9f9;
		min-height: 100vh;
		box-sizing: border-box;
	}
	.logo {
		text-align: center;
		margin-bottom: 80rpx;
	}
	.avatar-img {
		width: 160rpx;
		height: 160rpx;
		border-radius: 50%;
		object-fit: cover;
		border: 4rpx solid #f0f0f0;
	}
	.form-container {
		width: 100%;
		max-width: 500rpx;
		background-color: #fff;
		padding: 60rpx 40rpx;
		border-radius: 16rpx;
		box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.05);
	}
	.title {
		font-size: 36rpx;
		font-weight: bold;
		color: #333;
		text-align: center;
		margin-bottom: 60rpx;
	}
	.input-group {
		margin-bottom: 30rpx;
	}
	.input {
		width: 100%;
		height: 90rpx;
		padding: 0 20rpx;
		border: 2rpx solid #eee;
		border-radius: 8rpx;
		font-size: 28rpx;
		box-sizing: border-box;
	}
	.input:focus {
		border-color: #007aff;
		outline: none;
	}
	.btn {
		width: 100%;
		height: 90rpx;
		line-height: 90rpx;
		font-size: 30rpx;
		border-radius: 8rpx;
		margin-bottom: 30rpx;
	}
	.login-btn {
		background-color: #007aff;
		color: #fff;
	}
	.link-container {
		text-align: center;
		font-size: 26rpx;
		color: #666;
	}
	.link {
		color: #007aff;
		margin-left: 10rpx;
		text-decoration: underline;
		cursor: pointer;
		user-select: none;
	}
</style>